﻿using System;
using System.Collections.Generic;
using System.Text;
using CFSystem.JXC.IDAL;
using CFSystem.JXC.Model;
using System.Data;
using System.Data.OleDb;
using DBUtility;

namespace CFSystem.JXC.AccessDAL
{
    /// <summary>
    /// 库存异动原因设置
    /// </summary>
    public class InTransReasonSetting : InvTransReasonSetting
    {
        #region InvTransReasonSetting Members

        IList<InvTransReasonSettingInfo> InvTransReasonSetting.GetInTransReasonSettings()
        {
            string sqlSelect = "Select * from [tb_InvChangeReason]";

            OleDbDataReader dr = AccessHelper.ExecuteReader(AccessHelper.ConnectionString, CommandType.Text, sqlSelect);

            IList<InvTransReasonSettingInfo> Items = new List<InvTransReasonSettingInfo>();

            if (dr.HasRows)
            {
                while (dr.Read())
                {
                    Items.Add(GetReasonSettingInfo(dr));
                }
                dr.Close();
            }
            return Items;
        }

        private InvTransReasonSettingInfo GetReasonSettingInfo(OleDbDataReader dr)
        {
            InvTransReasonSettingInfo itrsi = new InvTransReasonSettingInfo();
            itrsi.InvTransReasonID = Convert.ToInt32(dr["ID"]);
            itrsi.InvTransReasonName = dr["Name"].ToString();
            itrsi.Type = dr["Type"].ToString();

            return itrsi;
        }

        InvTransReasonSettingInfo InvTransReasonSetting.GetInvTransReasonSetting(int InvTransReasonSettingID)
        {
            throw new NotImplementedException();
        }

        void InvTransReasonSetting.InsertInvTransReasonSetting(InvTransReasonSettingInfo InTransReasonSetting)
        {
            string sqlInsert = "insert into [tb_InvChangeReason]([Name],[Type]) values('" + InTransReasonSetting.InvTransReasonName + "', '"
                                          + InTransReasonSetting.Type + "' )";

            int returnCnt = AccessHelper.ExecuteNonQuery(AccessHelper.ConnectionString, CommandType.Text, sqlInsert);

        }

        void InvTransReasonSetting.DelInvTransReasonSettingByID(int InTransReasonSettingID)
        {
            string sqlDelete = "delete from [tb_InvChangeReason] where  [ID] =" + InTransReasonSettingID;

            int returnCnt = AccessHelper.ExecuteNonQuery(AccessHelper.ConnectionString, CommandType.Text, sqlDelete);

        }

        void InvTransReasonSetting.UpdateInvTransReasonSettingByID(InvTransReasonSettingInfo InvTransReasonSetting)
        {
            string sqlUpdate = "UPDATE [tb_InvChangeReason] SET [Name] = '" + InvTransReasonSetting.InvTransReasonName
                             + "', [Type] = '" + InvTransReasonSetting.Type
                             + "' WHERE [ID] = " + InvTransReasonSetting.InvTransReasonID;
            int resultCnt = AccessHelper.ExecuteNonQuery(AccessHelper.ConnectionString, CommandType.Text, sqlUpdate);

        }

        #endregion
    }
}
